package org.lisa.crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.lisa.crm.common.util.Result;
import org.lisa.crm.dao.CustomerOrderDao;
import org.lisa.crm.model.CustomerOrder;
import org.lisa.crm.model.OrderDetails;
import org.lisa.crm.service.CustomerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/2.
 */
@Service
public class CustomerOrderServiceImpl implements CustomerOrderService {

    @Autowired
    private CustomerOrderDao customerOrderDao;


    @Override
    //CustomerOrder customerOrder 参数列表
    public Map<String, Object> queryOrdersByCid(int cid, int page,int rows) {

        List<CustomerOrder> list=customerOrderDao.queryOrdersByCid(cid);

        //分页
        PageHelper.startPage(page,rows);

        //创建一个包装了分页信息的分页对象,将list作为入参
        PageInfo<CustomerOrder> info = new PageInfo<>(list);

        Map<String,Object> map=new HashMap<>();
        map.put("total",info.getTotal());
        map.put("rows",info.getList());

        return map;

    }

    @Override
    public Result<CustomerOrder> queryCustoemrOrderByOrderId(int orderId) {
        CustomerOrder customerOrder=customerOrderDao.queryCustoemrOrderByOrderId(orderId);
        return Result.success("查询成功",customerOrder);
    }

    @Override
    public Map<String, Object> queryOrderDetailsByOrderId(int orderId, int page, int rows) {

        List<OrderDetails> list =customerOrderDao.queryOrderDetailsByOrderId(orderId);

        //分页
        PageHelper.startPage(page,rows);


        //创建一个包装了分页信息的分页对象,将list作为入参
        PageInfo<OrderDetails> info = new PageInfo<>(list);

        Map<String,Object> map1=new HashMap<>();
        map1.put("total",info.getTotal());
        map1.put("rows",info.getList());

        return map1;
    }
}
